<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix"><span>启动广告</span></div>
    <div>
      <el-collapse v-model="activeNames">
        <el-collapse-item title="内容" name="3">
          <draggable element="ul" v-model="data.imglist">
            <div class="item" v-for="(item, i) in data.imglist" :key="i">
              <i class="el-icon-error cancal" @click="delImg(i)"></i>
              <div class="img_box"><Upload :tempUrl="item.url" @input="getimg($event, item)"></Upload></div>
              <div class="item_select">
                <div @click="selectlink(item, i)"><Linkdiv :linkdata="item.linkdata"></Linkdiv></div>

                <span class="tip">建议图片宽度750px，高度跟随第一张图片的高度变化</span>
              </div>
            </div>
            <el-button @click="addimg">添加</el-button>
          </draggable>
        </el-collapse-item>
        <el-collapse-item title="组件状态" name="1">
          <el-form>
            <el-form-item label="广告状态">
              <el-radio-group v-model="data.type">
                <el-radio :label="1">启用</el-radio>
                <el-radio :label="0">不启用</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="显示设置">
              <el-radio-group v-model="data.showtime">
                <el-radio :label="1">每次显示</el-radio>
                <el-radio :label="0">间隔时间显示</el-radio>
              </el-radio-group>
              <el-form-item label="间隔时间" v-if="data.showtime == 0">
                <div class="timeout">
                  <el-slider class="slider_item" :max="240" :min="1" v-model="data.stime"></el-slider>
                  <el-input-number v-model="data.stime" :controls="false" :min="1" :max="240"></el-input-number>
                </div>
              </el-form-item>
            </el-form-item>
          </el-form>
        </el-collapse-item>
        <el-collapse-item title="组件样式" name="2">
          <el-form>
            <el-form-item label="广告样式">
              <el-radio-group v-model="data.showtype">
                <el-radio :label="'full'">全屏</el-radio>
                <el-radio :label="'bot'">弹窗1</el-radio>
                <el-radio :label="'top'">弹窗2</el-radio>
              </el-radio-group>
              <div class="bg-color">
                <el-form size="medium" label-width="100px">
                  <el-form-item label="定时关闭" v-if="data.showtype == 'full'">
                    <el-radio-group @change="timechange" v-model="data.time">
                      <el-radio :label="0">关闭</el-radio>
                      <el-radio :label="3">3秒</el-radio>
                      <el-radio :label="5">5秒</el-radio>
                      <el-radio :label="10">10秒</el-radio>
                      <el-radio :label="15">15秒</el-radio>
                    </el-radio-group>
                  </el-form-item>
                  <el-form-item label="关闭按钮" v-if="data.time > 0 && data.showtype == 'full'">
                    <el-radio-group v-model="data.c_btns">
                      <el-radio :label="false">关闭</el-radio>
                      <el-radio :label="true">开启</el-radio>
                    </el-radio-group>
                  </el-form-item>
                  <el-form-item label="背景颜色" v-if="data.showtype != 'full'"><ColorPicker :color="data" :name="'bg'"></ColorPicker></el-form-item>
                  <el-form-item label="透明度" v-if="data.showtype != 'full'">
                    <div class="slider_box_d">
                      <el-slider class="slider_item" :max="100" v-model="data.opacity"></el-slider>
                      <el-input-number v-model="data.opacity" :controls="false" :min="0" :max="100"></el-input-number>
                    </div>
                  </el-form-item>
                </el-form>
              </div>
            </el-form-item>
          </el-form>
        </el-collapse-item>
      </el-collapse>
    </div>
  </el-card>
</template>

<script>
import Upload from '@/components/Upload/SingleImage2';
import ColorPicker from '@/components/ColorPicker/index';
import Linkdiv from '@/components/Link/index';
import draggable from 'vuedraggable';
export default {
  props: {
    data: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      activeNames: ['1', '2', '3']
    };
  },
  components: {
    draggable,
    Upload,
    ColorPicker,
    Linkdiv
  },

  methods: {
    selectlink(item, i) {
      this.acivedata = item;
      this.activid = i;
      this.$parent.showlinkselcet(item);
    },
    getAData(item) {
      this.acivedata.linkdata = item;
    },
    timechange(e) {
      if (e == 0) {
        this.data.c_btns = true;
      }
    },
    getimg(data, item) {
      item.url = data;
    },
    //删除图片
    delImg(i) {
      this.data.imglist.splice(i, 1);
    },
    addimg() {
      this.data.imglist.push({
        url: '',
        linkdata: {
          link: '',
          name: '',
          id: '',
          type: ''
        }
      });
    },
    change() {
      this.$emit('change', this.data);
    }
  }
};
</script>
<style lang="scss">
.slider_box_d {
  display: flex;
  .el-input-number {
    width: 80px;
    position: relative;
    &::after {
      content: '%';
      position: absolute;
      right: 10px;
      top: 0px;
    }

    .el-input {
      width: 80px;
    }
  }
}
.timeout {
  display: flex;
  .el-input-number {
    width: 120px;
    position: relative;
    &::after {
      content: 'min';
      position: absolute;
      right: 10px;
      top: 0px;
    }
  }
  .el-input {
    width: 120px;
  }
}
</style>
<style scoped lang="scss">
.bg-color {
  border: 1px solid #e9edef;
  box-sizing: border-box;
  padding: 20px 0;
  border-radius: 2px;
  background: #f4f6f8;
}
.item {
  position: relative;
  width: 100%;
  display: flex;
  cursor: pointer;
  background: #f4f6f8;
  border-radius: 2px;
  box-sizing: border-box;
  border: 1px solid #e9edef;
  margin-bottom: 10px;
  padding: 10px 10px;
  &:hover {
    .cancal {
      display: block;
    }
  }

  .cancal {
    font-size: 20px;
    position: absolute;
    right: 0px;
    top: 0px;
    cursor: pointer;
    display: none;
  }
}

.img_box {
  width: 60px;
  height: 60px;
}

.item_select {
  flex: 1;
  margin-left: 10px;
}

.select_link {
  background: #fff;
}

.select_btn {
  padding: 4px 6px;
  color: #2d8cf0;
  box-sizing: border-box;
  border: 1px solid #fff;
}

.select_btn:hover {
  border: 1px solid #2d8cf0;
}

.tip {
  display: block;
  font-family: PingFang SC;
  font-style: normal;
  font-weight: normal;
  font-size: 12px;
  line-height: 18px;
  color: #939799;
  /* margin-top: 8px; */
}
</style>
